from header_common import *
from header_operations import *
from header_parties import *
from header_items import *
from header_skills import *
from header_triggers import *
from header_troops import *

from module_constants import *

####################################################################################################################
#  Each trigger contains the following fields:
# 1) Check interval: How frequently this trigger will be checked
# 2) Delay interval: Time to wait before applying the consequences of the trigger
#    After its conditions have been evaluated as true.
# 3) Re-arm interval. How much time must pass after applying the consequences of the trigger for the trigger to become active again.
#    You can put the constant ti_once here to make sure that the trigger never becomes active again after it fires once.
# 4) Conditions block (list). This must be a valid operation block. See header_operations.py for reference.
#    Every time the trigger is checked, the conditions block will be executed.
#    If the conditions block returns true, the consequences block will be executed.
#    If the conditions block is empty, it is assumed that it always evaluates to true.
# 5) Consequences block (list). This must be a valid operation block. See header_operations.py for reference. 
####################################################################################################################

# Some constants for use below
merchant_inventory_space = 30
num_merchandise_goods = 36



triggers = [
# Tutorial:
  (0.1, 0, ti_once, [(map_free,0)], [(tutorial_box,"str_tutorial_map1")]),

    
# Wages:
  (1.0, 0, (7.0 * 24.0), [(eq,"$player_relation_to_vaegirs",rel_ally)], [(val_add,"$wages","$weekly_wage")]),
  (1.0, 0, (7.0 * 24.0), [(eq,"$player_relation_to_swadians",rel_ally)], [(val_add,"$wages","$weekly_wage")]),

#Initialize Towns
  (0.0, 0, ti_once, [], [
      (party_set_slot,"p_town_1", slot_party_type,         spt_town),
      (party_set_slot,"p_town_1", slot_town_center,        "scn_town_1_center"),
      (party_set_slot,"p_town_1", slot_town_castle,        "scn_town_1_castle"),
      (party_set_slot,"p_town_1", slot_town_tavern,        "scn_town_1_tavern"),
      (party_set_slot,"p_town_1", slot_town_store,         "scn_town_1_store"),
      (party_set_slot,"p_town_1", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_1", slot_town_arena,         "scn_town_1_arena"),
      (party_set_slot,"p_town_1", slot_town_tavernkeeper,  "trp_town_1_tavernkeeper"),
      (party_set_slot,"p_town_1", slot_town_weaponsmith,   "trp_town_1_weaponsmith"),
      (party_set_slot,"p_town_1", slot_town_armorer,       "trp_town_1_armorer"),
      (party_set_slot,"p_town_1", slot_town_merchant,      "trp_town_1_merchant"),
      (party_set_slot,"p_town_1", slot_town_mercs,         "p_town_1_mercs"),
      (party_set_slot,"p_town_1", slot_town_export_good,   "itm_linen"),
      (party_set_slot,"p_town_1", slot_town_export_rate,   70),
      (party_set_slot,"p_town_1", slot_town_import_good,   "itm_iron"),
      (party_set_slot,"p_town_1", slot_town_import_rate,   135),
      (party_set_slot,"p_town_1", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_1", slot_town_arena_melee_1_team_size,   1),
      (party_set_slot,"p_town_1", slot_town_arena_melee_2_num_teams,   4),
      (party_set_slot,"p_town_1", slot_town_arena_melee_2_team_size,   1),
      (party_set_slot,"p_town_1", slot_town_arena_melee_3_num_teams,   4),
      (party_set_slot,"p_town_1", slot_town_arena_melee_3_team_size,   1),
      (party_set_slot,"p_town_1", slot_town_arena_template, "mt_arena_melee_fight_no_ranged"),

      (party_set_slot,"p_town_2", slot_party_type,         spt_town),
      (party_set_slot,"p_town_2", slot_town_center,        "scn_town_2_center"),
      (party_set_slot,"p_town_2", slot_town_castle,        "scn_town_2_castle"),
      (party_set_slot,"p_town_2", slot_town_tavern,        "scn_town_2_tavern"),
      (party_set_slot,"p_town_2", slot_town_store,         "scn_town_2_store"),
      (party_set_slot,"p_town_2", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_2", slot_town_arena,         "scn_town_2_arena"),
      (party_set_slot,"p_town_2", slot_town_tavernkeeper,  "trp_town_2_tavernkeeper"),
      (party_set_slot,"p_town_2", slot_town_weaponsmith,   "trp_town_2_weaponsmith"),
      (party_set_slot,"p_town_2", slot_town_armorer,       "trp_town_2_armorer"),
      (party_set_slot,"p_town_2", slot_town_merchant,      "trp_town_2_merchant"),
      (party_set_slot,"p_town_2", slot_town_mercs,         "p_town_2_mercs"),
      (party_set_slot,"p_town_2", slot_town_export_good,   "itm_smoked_fish"),
      (party_set_slot,"p_town_2", slot_town_export_rate,   60),
      (party_set_slot,"p_town_2", slot_town_import_good,   "itm_wool"),
      (party_set_slot,"p_town_2", slot_town_import_rate,   135),
      (party_set_slot,"p_town_2", slot_town_arena_melee_1_num_teams,   4),
      (party_set_slot,"p_town_2", slot_town_arena_melee_1_team_size,   4),
      (party_set_slot,"p_town_2", slot_town_arena_melee_2_num_teams,   4),
      (party_set_slot,"p_town_2", slot_town_arena_melee_2_team_size,   6),
      (party_set_slot,"p_town_2", slot_town_arena_melee_3_num_teams,   4),
      (party_set_slot,"p_town_2", slot_town_arena_melee_3_team_size,   8),
      (party_set_slot,"p_town_2", slot_town_arena_template, "mt_arena_melee_fight"),
      
      (party_set_slot,"p_town_3", slot_party_type,         spt_town),
      (party_set_slot,"p_town_3", slot_town_center,        "scn_town_3_center"),
      (party_set_slot,"p_town_3", slot_town_castle,        "scn_town_3_castle"),
      (party_set_slot,"p_town_3", slot_town_tavern,        "scn_town_3_tavern"),
      (party_set_slot,"p_town_3", slot_town_store,         "scn_town_3_store"),
      (party_set_slot,"p_town_3", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_3", slot_town_arena,         "scn_town_3_arena"),
      (party_set_slot,"p_town_3", slot_town_tavernkeeper,  "trp_town_3_tavernkeeper"),
      (party_set_slot,"p_town_3", slot_town_weaponsmith,   "trp_town_3_weaponsmith"),
      (party_set_slot,"p_town_3", slot_town_armorer,       "trp_town_3_armorer"),
      (party_set_slot,"p_town_3", slot_town_merchant,      "trp_town_3_merchant"),
      (party_set_slot,"p_town_3", slot_town_mercs,         "p_town_3_mercs"),
      (party_set_slot,"p_town_3", slot_town_export_good,   "itm_wine"),
      (party_set_slot,"p_town_3", slot_town_export_rate,   70),
      (party_set_slot,"p_town_3", slot_town_import_good,   "itm_dried_meat"),
      (party_set_slot,"p_town_3", slot_town_import_rate,   135),
      (party_set_slot,"p_town_3", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_3", slot_town_arena_melee_1_team_size,   8),
      (party_set_slot,"p_town_3", slot_town_arena_melee_2_num_teams,   2),
      (party_set_slot,"p_town_3", slot_town_arena_melee_2_team_size,   8),
      (party_set_slot,"p_town_3", slot_town_arena_melee_3_num_teams,   2),
      (party_set_slot,"p_town_3", slot_town_arena_melee_3_team_size,   8),
      (party_set_slot,"p_town_3", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_4", slot_party_type,         spt_town),
      (party_set_slot,"p_town_4", slot_town_center,        "scn_town_4_center"),
      (party_set_slot,"p_town_4", slot_town_castle,        "scn_town_4_castle"),
      (party_set_slot,"p_town_4", slot_town_tavern,        "scn_town_4_tavern"),
      (party_set_slot,"p_town_4", slot_town_store,         "scn_town_4_store"),
      (party_set_slot,"p_town_4", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_4", slot_town_arena,         "scn_town_4_arena"),
      (party_set_slot,"p_town_4", slot_town_tavernkeeper,  "trp_town_4_tavernkeeper"),
      (party_set_slot,"p_town_4", slot_town_weaponsmith,   "trp_town_4_weaponsmith"),
      (party_set_slot,"p_town_4", slot_town_armorer,       "trp_town_4_armorer"),
      (party_set_slot,"p_town_4", slot_town_merchant,      "trp_town_4_merchant"),
      (party_set_slot,"p_town_4", slot_town_mercs,         "p_town_4_mercs"),
      (party_set_slot,"p_town_4", slot_town_export_good,   "itm_oil"),
      (party_set_slot,"p_town_4", slot_town_export_rate,   70),
      (party_set_slot,"p_town_4", slot_town_import_good,   "itm_furs"),
      (party_set_slot,"p_town_4", slot_town_import_rate,   140),
      (party_set_slot,"p_town_4", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_4", slot_town_arena_melee_1_team_size,   8),
      (party_set_slot,"p_town_4", slot_town_arena_melee_2_num_teams,   3),
      (party_set_slot,"p_town_4", slot_town_arena_melee_2_team_size,   8),
      (party_set_slot,"p_town_4", slot_town_arena_melee_3_num_teams,   2),
      (party_set_slot,"p_town_4", slot_town_arena_melee_3_team_size,   5),
      (party_set_slot,"p_town_4", slot_town_arena_template, "mt_arena_melee_fight"),
      
      (party_set_slot,"p_town_5", slot_party_type,         spt_town),
      (party_set_slot,"p_town_5", slot_town_center,        "scn_town_5_center"),
      (party_set_slot,"p_town_5", slot_town_castle,        "scn_town_5_castle"),
      (party_set_slot,"p_town_5", slot_town_tavern,        "scn_town_5_tavern"),
      (party_set_slot,"p_town_5", slot_town_store,         "scn_town_5_store"),
      (party_set_slot,"p_town_5", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_5", slot_town_arena,         "scn_town_5_arena"),
      (party_set_slot,"p_town_5", slot_town_tavernkeeper,  "trp_town_5_tavernkeeper"),
      (party_set_slot,"p_town_5", slot_town_weaponsmith,   "trp_town_5_weaponsmith"),
      (party_set_slot,"p_town_5", slot_town_armorer,       "trp_town_5_armorer"),
      (party_set_slot,"p_town_5", slot_town_merchant,      "trp_town_5_merchant"),
      (party_set_slot,"p_town_5", slot_town_mercs,         "p_town_5_mercs"),
      (party_set_slot,"p_town_5", slot_town_export_good,   "itm_velvet"),
      (party_set_slot,"p_town_5", slot_town_export_rate,   78),
      (party_set_slot,"p_town_5", slot_town_import_good,   "itm_pottery"),
      (party_set_slot,"p_town_5", slot_town_import_rate,   140),
      (party_set_slot,"p_town_5", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_5", slot_town_arena_melee_1_team_size,   3),
      (party_set_slot,"p_town_5", slot_town_arena_melee_2_num_teams,   2),
      (party_set_slot,"p_town_5", slot_town_arena_melee_2_team_size,   5),
      (party_set_slot,"p_town_5", slot_town_arena_melee_3_num_teams,   2),
      (party_set_slot,"p_town_5", slot_town_arena_melee_3_team_size,   8),
      (party_set_slot,"p_town_5", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_6", slot_party_type,         spt_town),
      (party_set_slot,"p_town_6", slot_town_center,        "scn_town_6_center"),
      (party_set_slot,"p_town_6", slot_town_castle,        "scn_town_6_castle"),
      (party_set_slot,"p_town_6", slot_town_tavern,        "scn_town_6_tavern"),
      (party_set_slot,"p_town_6", slot_town_store,         "scn_town_6_store"),
      (party_set_slot,"p_town_6", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_6", slot_town_arena,         "scn_town_6_arena"),
      (party_set_slot,"p_town_6", slot_town_tavernkeeper,  "trp_town_6_tavernkeeper"),
      (party_set_slot,"p_town_6", slot_town_weaponsmith,   "trp_town_6_weaponsmith"),
      (party_set_slot,"p_town_6", slot_town_armorer,       "trp_town_6_armorer"),
      (party_set_slot,"p_town_6", slot_town_merchant,      "trp_town_6_merchant"),
      (party_set_slot,"p_town_6", slot_town_mercs,         "p_town_6_mercs"),
      (party_set_slot,"p_town_6", slot_town_export_good,   "itm_ale"),
      (party_set_slot,"p_town_6", slot_town_export_rate,   64),
      (party_set_slot,"p_town_6", slot_town_import_good,   "itm_spice"),
      (party_set_slot,"p_town_6", slot_town_import_rate,   130),
      (party_set_slot,"p_town_6", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_6", slot_town_arena_melee_1_team_size,   4),
      (party_set_slot,"p_town_6", slot_town_arena_melee_2_num_teams,   3),
      (party_set_slot,"p_town_6", slot_town_arena_melee_2_team_size,   4),
      (party_set_slot,"p_town_6", slot_town_arena_melee_3_num_teams,   3),
      (party_set_slot,"p_town_6", slot_town_arena_melee_3_team_size,   6),
      (party_set_slot,"p_town_6", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_7", slot_party_type,         spt_town),
      (party_set_slot,"p_town_7", slot_town_center,        "scn_town_7_center"),
      (party_set_slot,"p_town_7", slot_town_castle,        "scn_town_7_castle"),
      (party_set_slot,"p_town_7", slot_town_tavern,        "scn_town_7_tavern"),
      (party_set_slot,"p_town_7", slot_town_store,         "scn_town_7_store"),
      (party_set_slot,"p_town_7", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_7", slot_town_arena,         "scn_town_7_arena"),
      (party_set_slot,"p_town_7", slot_town_tavernkeeper,  "trp_town_7_tavernkeeper"),
      (party_set_slot,"p_town_7", slot_town_weaponsmith,   "trp_town_7_weaponsmith"),
      (party_set_slot,"p_town_7", slot_town_armorer,       "trp_town_7_armorer"),
      (party_set_slot,"p_town_7", slot_town_merchant,      "trp_town_7_merchant"),
      (party_set_slot,"p_town_7", slot_town_mercs,         "p_town_7_mercs"),
      (party_set_slot,"p_town_7", slot_town_export_good,   "itm_grain"),
      (party_set_slot,"p_town_7", slot_town_export_rate,   58),
      (party_set_slot,"p_town_7", slot_town_import_good,   "itm_smoked_fish"),
      (party_set_slot,"p_town_7", slot_town_import_rate,   142),
      (party_set_slot,"p_town_7", slot_town_arena_melee_1_num_teams,   4),
      (party_set_slot,"p_town_7", slot_town_arena_melee_1_team_size,   4),
      (party_set_slot,"p_town_7", slot_town_arena_melee_2_num_teams,   4),
      (party_set_slot,"p_town_7", slot_town_arena_melee_2_team_size,   6),
      (party_set_slot,"p_town_7", slot_town_arena_melee_3_num_teams,   4),
      (party_set_slot,"p_town_7", slot_town_arena_melee_3_team_size,   8),
      (party_set_slot,"p_town_7", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_8", slot_party_type,         spt_town),
      (party_set_slot,"p_town_8", slot_town_center,        "scn_town_8_center"),
      (party_set_slot,"p_town_8", slot_town_castle,        "scn_town_8_castle"),
      (party_set_slot,"p_town_8", slot_town_tavern,        "scn_town_8_tavern"),
      (party_set_slot,"p_town_8", slot_town_store,         "scn_town_8_store"),
      (party_set_slot,"p_town_8", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_8", slot_town_arena,         "scn_town_8_arena"),
      (party_set_slot,"p_town_8", slot_town_tavernkeeper,  "trp_town_8_tavernkeeper"),
      (party_set_slot,"p_town_8", slot_town_weaponsmith,   "trp_town_8_weaponsmith"),
      (party_set_slot,"p_town_8", slot_town_armorer,       "trp_town_8_armorer"),
      (party_set_slot,"p_town_8", slot_town_merchant,      "trp_town_8_merchant"),
      (party_set_slot,"p_town_8", slot_town_mercs,         "p_town_8_mercs"),
      (party_set_slot,"p_town_8", slot_town_export_good,   "itm_wool"),
      (party_set_slot,"p_town_8", slot_town_export_rate,   65),
      (party_set_slot,"p_town_8", slot_town_import_good,   "itm_velvet"),
      (party_set_slot,"p_town_8", slot_town_import_rate,   129),
      (party_set_slot,"p_town_8", slot_town_arena_melee_1_num_teams,   3),
      (party_set_slot,"p_town_8", slot_town_arena_melee_1_team_size,   1),
      (party_set_slot,"p_town_8", slot_town_arena_melee_2_num_teams,   3),
      (party_set_slot,"p_town_8", slot_town_arena_melee_2_team_size,   3),
      (party_set_slot,"p_town_8", slot_town_arena_melee_3_num_teams,   3),
      (party_set_slot,"p_town_8", slot_town_arena_melee_3_team_size,   7),
      (party_set_slot,"p_town_8", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_9", slot_party_type,         spt_town),
      (party_set_slot,"p_town_9", slot_town_center,        "scn_town_9_center"),
      (party_set_slot,"p_town_9", slot_town_castle,        "scn_town_9_castle"),
      (party_set_slot,"p_town_9", slot_town_tavern,        "scn_town_9_tavern"),
      (party_set_slot,"p_town_9", slot_town_store,         "scn_town_9_store"),
      (party_set_slot,"p_town_9", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_9", slot_town_arena,         "scn_town_9_arena"),
      (party_set_slot,"p_town_9", slot_town_tavernkeeper,  "trp_town_9_tavernkeeper"),
      (party_set_slot,"p_town_9", slot_town_weaponsmith,   "trp_town_9_weaponsmith"),
      (party_set_slot,"p_town_9", slot_town_armorer,       "trp_town_9_armorer"),
      (party_set_slot,"p_town_9", slot_town_merchant,      "trp_town_9_merchant"),
      (party_set_slot,"p_town_9", slot_town_mercs,         "p_town_9_mercs"),
      (party_set_slot,"p_town_9", slot_town_export_good,   "itm_furs"),
      (party_set_slot,"p_town_9", slot_town_export_rate,   65),
      (party_set_slot,"p_town_9", slot_town_import_good,   "itm_ale"),
      (party_set_slot,"p_town_9", slot_town_import_rate,   140),
      (party_set_slot,"p_town_9", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_9", slot_town_arena_melee_1_team_size,   2),
      (party_set_slot,"p_town_9", slot_town_arena_melee_2_num_teams,   2),
      (party_set_slot,"p_town_9", slot_town_arena_melee_2_team_size,   5),
      (party_set_slot,"p_town_9", slot_town_arena_melee_3_num_teams,   2),
      (party_set_slot,"p_town_9", slot_town_arena_melee_3_team_size,   8),
      (party_set_slot,"p_town_9", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_10", slot_party_type,         spt_town),
      (party_set_slot,"p_town_10", slot_town_center,        "scn_town_10_center"),
      (party_set_slot,"p_town_10", slot_town_castle,        "scn_town_10_castle"),
      (party_set_slot,"p_town_10", slot_town_tavern,        "scn_town_10_tavern"),
      (party_set_slot,"p_town_10", slot_town_store,         "scn_town_10_store"),
      (party_set_slot,"p_town_10", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_10", slot_town_arena,         "scn_town_10_arena"),
      (party_set_slot,"p_town_10", slot_town_tavernkeeper,  "trp_town_10_tavernkeeper"),
      (party_set_slot,"p_town_10", slot_town_weaponsmith,   "trp_town_10_weaponsmith"),
      (party_set_slot,"p_town_10", slot_town_armorer,       "trp_town_10_armorer"),
      (party_set_slot,"p_town_10", slot_town_merchant,      "trp_town_10_merchant"),
      (party_set_slot,"p_town_10", slot_town_mercs,         "p_town_10_mercs"),
      (party_set_slot,"p_town_10", slot_town_export_good,   "itm_spice"),
      (party_set_slot,"p_town_10", slot_town_export_rate,   80),
      (party_set_slot,"p_town_10", slot_town_import_good,   "itm_grain"),
      (party_set_slot,"p_town_10", slot_town_import_rate,   142),
      (party_set_slot,"p_town_10", slot_town_import_good_2, "itm_tools"),
      (party_set_slot,"p_town_10", slot_town_import_rate_2, 130),
      (party_set_slot,"p_town_10", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_10", slot_town_arena_melee_1_team_size,   3),
      (party_set_slot,"p_town_10", slot_town_arena_melee_2_num_teams,   2),
      (party_set_slot,"p_town_10", slot_town_arena_melee_2_team_size,   5),
      (party_set_slot,"p_town_10", slot_town_arena_melee_3_num_teams,   2),
      (party_set_slot,"p_town_10", slot_town_arena_melee_3_team_size,   8),
      (party_set_slot,"p_town_10", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_11", slot_party_type,         spt_town),
      (party_set_slot,"p_town_11", slot_town_center,        "scn_town_11_center"),
      (party_set_slot,"p_town_11", slot_town_castle,        "scn_town_11_castle"),
      (party_set_slot,"p_town_11", slot_town_tavern,        "scn_town_11_tavern"),
      (party_set_slot,"p_town_11", slot_town_store,         "scn_town_11_store"),
      (party_set_slot,"p_town_11", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_11", slot_town_arena,         "scn_town_11_arena"),
      (party_set_slot,"p_town_11", slot_town_tavernkeeper,  "trp_town_11_tavernkeeper"),
      (party_set_slot,"p_town_11", slot_town_weaponsmith,   "trp_town_11_weaponsmith"),
      (party_set_slot,"p_town_11", slot_town_armorer,       "trp_town_11_armorer"),
      (party_set_slot,"p_town_11", slot_town_merchant,      "trp_town_11_merchant"),
      (party_set_slot,"p_town_11", slot_town_mercs,         "p_town_11_mercs"),
      (party_set_slot,"p_town_11", slot_town_export_good,   "itm_iron"),
      (party_set_slot,"p_town_11", slot_town_export_rate,   60),
      (party_set_slot,"p_town_11", slot_town_import_good,   "itm_dried_meat"),
      (party_set_slot,"p_town_11", slot_town_import_rate,   133),
      (party_set_slot,"p_town_11", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_11", slot_town_arena_melee_1_team_size,   8),
      (party_set_slot,"p_town_11", slot_town_arena_melee_2_num_teams,   3),
      (party_set_slot,"p_town_11", slot_town_arena_melee_2_team_size,   4),
      (party_set_slot,"p_town_11", slot_town_arena_melee_3_num_teams,   3),
      (party_set_slot,"p_town_11", slot_town_arena_melee_3_team_size,   6),
      (party_set_slot,"p_town_11", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_12", slot_party_type,         spt_town),
      (party_set_slot,"p_town_12", slot_town_center,        "scn_town_12_center"),
      (party_set_slot,"p_town_12", slot_town_castle,        "scn_town_12_castle"),
      (party_set_slot,"p_town_12", slot_town_tavern,        "scn_town_12_tavern"),
      (party_set_slot,"p_town_12", slot_town_store,         "scn_town_12_store"),
      (party_set_slot,"p_town_12", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_12", slot_town_arena,         "scn_town_12_arena"),
      (party_set_slot,"p_town_12", slot_town_tavernkeeper,  "trp_town_12_tavernkeeper"),
      (party_set_slot,"p_town_12", slot_town_weaponsmith,   "trp_town_12_weaponsmith"),
      (party_set_slot,"p_town_12", slot_town_armorer,       "trp_town_12_armorer"),
      (party_set_slot,"p_town_12", slot_town_merchant,      "trp_town_12_merchant"),
      (party_set_slot,"p_town_12", slot_town_mercs,         "p_town_12_mercs"),
      (party_set_slot,"p_town_12", slot_town_export_good,   "itm_smoked_fish"),
      (party_set_slot,"p_town_12", slot_town_export_rate,   57),
      (party_set_slot,"p_town_12", slot_town_import_good,   "itm_wine"),
      (party_set_slot,"p_town_12", slot_town_import_rate,   133),
      (party_set_slot,"p_town_12", slot_town_arena_melee_1_num_teams,   3),
      (party_set_slot,"p_town_12", slot_town_arena_melee_1_team_size,   8),
      (party_set_slot,"p_town_12", slot_town_arena_melee_2_num_teams,   4),
      (party_set_slot,"p_town_12", slot_town_arena_melee_2_team_size,   6),
      (party_set_slot,"p_town_12", slot_town_arena_melee_3_num_teams,   4),
      (party_set_slot,"p_town_12", slot_town_arena_melee_3_team_size,   5),
      (party_set_slot,"p_town_12", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_13", slot_party_type,         spt_town),
      (party_set_slot,"p_town_13", slot_town_center,        "scn_town_13_center"),
      (party_set_slot,"p_town_13", slot_town_castle,        "scn_town_13_castle"),
      (party_set_slot,"p_town_13", slot_town_tavern,        "scn_town_13_tavern"),
      (party_set_slot,"p_town_13", slot_town_store,         "scn_town_13_store"),
      (party_set_slot,"p_town_13", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_13", slot_town_arena,         "scn_town_13_arena"),
      (party_set_slot,"p_town_13", slot_town_tavernkeeper,  "trp_town_13_tavernkeeper"),
      (party_set_slot,"p_town_13", slot_town_weaponsmith,   "trp_town_13_weaponsmith"),
      (party_set_slot,"p_town_13", slot_town_armorer,       "trp_town_13_armorer"),
      (party_set_slot,"p_town_13", slot_town_merchant,      "trp_town_13_merchant"),
      (party_set_slot,"p_town_13", slot_town_mercs,         "p_town_13_mercs"),
      (party_set_slot,"p_town_13", slot_town_export_good,   "itm_dried_meat"),
      (party_set_slot,"p_town_13", slot_town_export_rate,   60),
      (party_set_slot,"p_town_13", slot_town_import_good,   "itm_oil"),
      (party_set_slot,"p_town_13", slot_town_import_rate,   130),
      (party_set_slot,"p_town_13", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_13", slot_town_arena_melee_1_team_size,   8),
      (party_set_slot,"p_town_13", slot_town_arena_melee_2_num_teams,   4),
      (party_set_slot,"p_town_13", slot_town_arena_melee_2_team_size,   5),
      (party_set_slot,"p_town_13", slot_town_arena_melee_3_num_teams,   4),
      (party_set_slot,"p_town_13", slot_town_arena_melee_3_team_size,   7),
      (party_set_slot,"p_town_13", slot_town_arena_template, "mt_arena_melee_fight"),

      (party_set_slot,"p_town_14", slot_party_type,         spt_town),
      (party_set_slot,"p_town_14", slot_town_center,        "scn_town_14_center"),
      (party_set_slot,"p_town_14", slot_town_castle,        "scn_town_14_castle"),
      (party_set_slot,"p_town_14", slot_town_tavern,        "scn_town_14_tavern"),
      (party_set_slot,"p_town_14", slot_town_store,         "scn_town_14_store"),
      (party_set_slot,"p_town_14", slot_town_gate,          "scn_town_1_gate"),
      (party_set_slot,"p_town_14", slot_town_arena,         "scn_town_14_arena"),
      (party_set_slot,"p_town_14", slot_town_tavernkeeper,  "trp_town_14_tavernkeeper"),
      (party_set_slot,"p_town_14", slot_town_weaponsmith,   "trp_town_14_weaponsmith"),
      (party_set_slot,"p_town_14", slot_town_armorer,       "trp_town_14_armorer"),
      (party_set_slot,"p_town_14", slot_town_merchant,      "trp_town_14_merchant"),
      (party_set_slot,"p_town_14", slot_town_mercs,         "p_town_14_mercs"),
      (party_set_slot,"p_town_14", slot_town_export_good,   "itm_pottery"),
      (party_set_slot,"p_town_14", slot_town_export_rate,   67),
      (party_set_slot,"p_town_14", slot_town_import_good,   "itm_linen"),
      (party_set_slot,"p_town_14", slot_town_import_rate,   130),
      (party_set_slot,"p_town_14", slot_town_arena_melee_1_num_teams,   2),
      (party_set_slot,"p_town_14", slot_town_arena_melee_1_team_size,   4),
      (party_set_slot,"p_town_14", slot_town_arena_melee_2_num_teams,   2),
      (party_set_slot,"p_town_14", slot_town_arena_melee_2_team_size,   5),
      (party_set_slot,"p_town_14", slot_town_arena_melee_3_num_teams,   2),
      (party_set_slot,"p_town_14", slot_town_arena_melee_3_team_size,   6),
      (party_set_slot,"p_town_14", slot_town_arena_template, "mt_arena_melee_fight"),

# Castles:
      (party_set_slot,"p_castle_1", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_1", slot_castle_exterior,   "scn_castle_1_exterior"),
      (party_set_slot,"p_castle_1", slot_castle_interior,   "scn_castle_1_interior"),

      (party_set_slot,"p_castle_2", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_2", slot_castle_exterior,   "scn_castle_2_exterior"),
      (party_set_slot,"p_castle_2", slot_castle_interior,   "scn_castle_2_interior"),

      (party_set_slot,"p_castle_3", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_3", slot_castle_exterior,   "scn_castle_3_exterior"),
      (party_set_slot,"p_castle_4", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_4", slot_castle_exterior,   "scn_castle_4_exterior"),
      (party_set_slot,"p_castle_5", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_5", slot_castle_exterior,   "scn_castle_5_exterior"),
      (party_set_slot,"p_castle_6", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_6", slot_castle_exterior,   "scn_castle_6_exterior"),
      (party_set_slot,"p_castle_7", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_7", slot_castle_exterior,   "scn_castle_7_exterior"),
      (party_set_slot,"p_castle_8", slot_party_type,         spt_castle),
      (party_set_slot,"p_castle_8", slot_castle_exterior,   "scn_castle_8_exterior"),

      ]),

# Refresh Merchants
  (0.0, 0, 24.0, [], [
                      (reset_item_probabilities,100),
                      (set_merchandise_modifier_quality,120),


                      (reset_item_probabilities,100),(set_item_probability_in_merchandise,"itm_tools",700),
                      (troop_add_merchandise,"trp_zendar_merchant",itp_type_goods,num_merchandise_goods),
                      (reset_item_probabilities,100),(set_item_probability_in_merchandise,"itm_salt",700),
                      (troop_add_merchandise,"trp_salt_mine_merchant",itp_type_goods,num_merchandise_goods),

                      # Add trade goods to merchant inventories
                      (try_for_range,reg(2),towns_begin,towns_end),
                      (reset_item_probabilities,100),
                      (party_get_slot,reg(6),reg(2),slot_town_export_good),
                      (party_get_slot,reg(8),reg(2),slot_town_export_good_2),
                      (party_get_slot,reg(10),reg(2),slot_town_merchant),
                      (set_item_probability_in_merchandise,reg(6),700),
                      (set_item_probability_in_merchandise,reg(8),700),
                      (troop_add_merchandise,reg(10),itp_type_goods,num_merchandise_goods),

#                      (assign,"$pin_town",reg(2)),
#                      (call_script,"script_get_town_properties"),
#                      (assign,reg(3),4000000),
#                      (val_div,reg(3),"$pout_export_rate"),
#                      (val_div,reg(3),"$pout_export_rate"),
#                      (set_item_probability_in_merchandise,"$pout_export_good",700),
#                      (troop_add_merchandise,"$pout_trp_merchant",itp_type_goods,num_merchandise_goods),
                      (end_try,0),

                      # Add horsess to merchant inventories
                      (reset_item_probabilities,100),
                      (try_for_range,reg(2),goods_merchants_begin,goods_merchants_end),
                      (troop_add_merchandise,reg(2),itp_type_horse,8),
                      (troop_ensure_inventory_space,reg(2),merchant_inventory_space),
                      (store_troop_gold, reg(6),reg(2)),
                      (lt,reg(6),800),
                      (store_random,reg(8),100),
                      (val_add,reg(8),200),
                      (troop_add_gold,reg(2),reg(8)),
                      (end_try,0),
                     ]),

# Refresh Armor sellers
  (0.0, 0, 24.0, [], [
                      (reset_item_probabilities,100),
                      (set_merchandise_modifier_quality,120),
                      (try_for_range,reg(2),armor_merchants_begin,armor_merchants_end),
                      (troop_add_merchandise,reg(2),itp_type_body_armor,16),
                      (troop_add_merchandise,reg(2),itp_type_head_armor,16),
                      (troop_add_merchandise,reg(2),itp_type_foot_armor,8),
                      (troop_add_merchandise,reg(2),itp_type_hand_armor,4),
                      (troop_ensure_inventory_space,reg(2),merchant_inventory_space),
                      (store_troop_gold, reg(6),reg(2)),
                      (lt,reg(6),500),
                      (store_random,reg(8),100),
                      (val_add,reg(8),200),
                      (troop_add_gold,reg(2),reg(8)),
                      (end_try,0),
                     ]),


# Refresh Weapon sellers
  (0.0, 0, 24.0, [], [
                      (reset_item_probabilities,100),
                      (set_merchandise_modifier_quality,120),
                      (try_for_range,reg(2),weapon_merchants_begin,weapon_merchants_end),
                      (troop_add_merchandise,reg(2),itp_type_one_handed_wpn,5),
                      (troop_add_merchandise,reg(2),itp_type_two_handed_wpn,5),
                      (troop_add_merchandise,reg(2),itp_type_polearm,5),
                      (troop_add_merchandise,reg(2),itp_type_shield,6),
                      (troop_add_merchandise,reg(2),itp_type_bow,4),
                      (troop_add_merchandise,reg(2),itp_type_crossbow,3),
                      (troop_add_merchandise,reg(2),itp_type_thrown,5),
                      (troop_add_merchandise,reg(2),itp_type_arrows,2),
                      (troop_add_merchandise,reg(2),itp_type_bolts,2),
                      (troop_ensure_inventory_space,reg(2),merchant_inventory_space),
                      (store_troop_gold, reg(6),reg(2)),
                      (lt,reg(6),600),
                      (store_random,reg(8),100),
                      (val_add,reg(8),200),
                      (troop_add_gold,reg(2),reg(8)),
                      (end_try,0),
                     ]),


# Refresh Tavernkeepers
  (24.0, 0, 0.0, [], [
    # Refresh Zendar
                      (try_begin,0),
                      (assign,reg(2),"p_zendar_mercs"),
                      (store_party_size,reg(6),reg(2)),
                      (lt,reg(6),20),
                      (store_random,reg(7),4),
                      (val_add,reg(7),1),
                      (party_add_members,reg(2),"trp_townsman",reg(7)),
                      (store_random,reg(8),2),
                      (party_add_members,reg(2),"trp_watchman",reg(8)),
                      (end_try,0),
    # Refresh Swadians
                      (try_for_range,reg(2),swadian_merc_parties_begin,swadian_merc_parties_end),
                      (store_party_size,reg(6),reg(2)),
                      (lt,reg(6),20),
                      (store_random,reg(7),4),
                      (val_add,reg(7),1),
                      (party_add_members,reg(2),"trp_swadian_peasant",reg(7)),
                      (store_random,reg(8),2),
                      (party_add_members,reg(2),"trp_swadian_militia",reg(8)),
                      (end_try,0),
    # Refresh Vaegirs
                      (try_for_range,reg(2),vaegir_merc_parties_begin,vaegir_merc_parties_end),
                      (store_party_size,reg(6),reg(2)),
                      (lt,reg(6),20),
                      (store_random,reg(7),4),
                      (val_add,reg(7),1),
                      (party_add_members,reg(2),"trp_vaegir_peasant",reg(7)),
                      (store_random,reg(8),2),
                      (party_add_members,reg(2),"trp_vaegir_footman",reg(8)),
                      (end_try,0),
                     ]),


#############

#Captivity:

#  (1.0, 0, 0.0, [],
#   [
#       (ge,"$captivity_mode",1),
#       (store_current_hours,reg(1)),
#       (val_sub,reg(1),"$captivity_end_time"),
#       (ge,reg(1),0),
#       (display_message,"str_nobleman_reached_destination"),
#       (jump_to_menu,"$captivity_end_menu"),
#    ]),


  (1.0, 0, ti_once, [], [(assign,"$peak_river_pirates",6)]),
  (3.7, 0, 0.0, [#[store0_distance_to_town_from_party,zendar],[lt,reg(0),40],
                 (store_num_parties_of_template, reg(2), "pt_river_pirates"),
                 (lt,reg(2),"$peak_river_pirates")],
                    [(set_spawn_radius,1),(spawn_around_party,"p_river_pirate_spawn_point","pt_river_pirates")]),

  (5.7, 0, 0.0, [(store_num_parties_created,reg(3),"pt_manhunters"),
                 (lt,reg(3),num_max_zendar_manhunters),
                 (store_num_parties_of_template, reg(2), "pt_manhunters"), (lt,reg(2),3)],
                       [(set_spawn_radius,1),(spawn_around_party,"p_zendar","pt_manhunters")]),
  (5.2, 0, 0.0, [(store_num_parties_created,reg(3),"pt_peasant"),(lt,reg(3),num_max_zendar_peasants),
                 (store_num_parties_of_template, reg(2), "pt_peasant"), (lt,reg(2),3)],
                          [(set_spawn_radius,1),(spawn_around_party,"p_zendar","pt_peasant")]),
  

  (0.0, 0, 0.0, [(neq,"$quest_accepted_zendar_river_pirates",0),(eq,"$quest_complete_zendar_river_pirates",0)],
   [
    (store_num_parties_destroyed_by_player, ":num_river_pirates_destroyed", "pt_river_pirates"),
    (assign, ":percentage", 100),
    (val_mul, ":percentage", ":num_river_pirates_destroyed"),
    (val_div, ":percentage", num_max_river_pirates),
    (set_quest_progression, "qst_hunt_down_river_pirates", ":percentage"),
   ]),
  
  (0.1, 0, ti_once, [(store_num_parties_destroyed_by_player, ":num_river_pirates_destroyed", "pt_river_pirates"),
                     (ge,":num_river_pirates_destroyed",num_max_river_pirates)],
                          [(assign,"$quest_complete_zendar_river_pirates",1),
                           (set_quest_progression, "qst_hunt_down_river_pirates", 100),
                           (assign,"$peak_river_pirates",2)]),
 

  (0.0, 0.0, ti_once, [], [[assign,"$player_relation_to_swadians", rel_neutral]]),
  (0.0, 0.0, ti_once, [], [[assign,"$player_relation_to_vaegirs",    rel_neutral]]),

#Tax Collectors
# Prisoner Trains
  (4.1, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_prisoner_train"),
                         (assign, "$pin_limit", peak_prisoner_trains),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                         (party_set_ai_behavior,"$pout_party",ai_bhvr_travel_to_party),
                         (party_set_ai_object,"$pout_party","$pout_town"),
                    ]),

  (4.1, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_prisoner_train"),
                         (assign, "$pin_limit", peak_prisoner_trains),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                         (party_set_ai_behavior,"$pout_party",ai_bhvr_travel_to_party),
                         (party_set_ai_object,"$pout_party","$pout_town"),
                    ]),

  (5.0, 0, 0, [(store_random_party_of_template, reg(2), "pt_swadian_prisoner_train"),
               (party_is_in_any_town,reg(2)),
               ],
              [
                  (assign, "$pin_faction","fac_swadians"),
                  (call_script,"script_select_faction_town"),
                  (party_set_ai_behavior,reg(2),ai_bhvr_travel_to_party),
                  (party_set_ai_object,reg(2),"$pout_town"),
            ]),

  (5.0, 0, 0, [(store_random_party_of_template, reg(2), "pt_vaegir_prisoner_train"),
               (party_is_in_any_town,reg(2)),
               ],
              [
                  (assign, "$pin_faction","fac_vaegirs"),
                  (call_script,"script_select_faction_town"),
                  (party_set_ai_behavior,reg(2),ai_bhvr_travel_to_party),
                  (party_set_ai_object,reg(2),"$pout_town"),
            ]),

#Caravans
  (4.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_caravan"),
                         (assign, "$pin_limit", peak_kingdom_caravans),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                         (party_set_ai_behavior,"$pout_party",ai_bhvr_travel_to_party),
                         (party_set_ai_object,"$pout_party","$pout_town"),
                    ]),

  (4.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_caravan"),
                         (assign, "$pin_limit", peak_kingdom_caravans),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                         (party_set_ai_behavior,"$pout_party",ai_bhvr_travel_to_party),
                         (party_set_ai_object,"$pout_party","$pout_town"),
                    ]),

  (5.0, 0, 0, [(store_random_party_of_template, reg(2), "pt_swadian_caravan"),
               (party_is_in_any_town,reg(2)),
               ],
              [
                  (assign, "$pin_faction","fac_swadians"),
                  (call_script,"script_select_faction_town"),
                  (party_set_ai_behavior,reg(2),ai_bhvr_travel_to_party),
                  (party_set_ai_object,reg(2),"$pout_town"),
            ]),
  
  (5.0, 0, 0, [(store_random_party_of_template, reg(2), "pt_vaegir_caravan"),
               (party_is_in_any_town,reg(2)),
               ],
              [
                  (assign, "$pin_faction","fac_vaegirs"),
                  (call_script,"script_select_faction_town"),
                  (party_set_ai_behavior,reg(2),ai_bhvr_travel_to_party),
                  (party_set_ai_object,reg(2),"$pout_town"),
            ]),
  
  (2.0, 0, 0.0, [(eq, "$caravan_escort_state", 1),
                 (get_party_ai_object,reg(1),"$caravan_escort_party_id"),
                 (neq,reg(1),"$caravan_escort_destination_town"),
                ],
                     [(assign,"$caravan_escort_state",0),
                      (add_xp_as_reward,100),
                      ]),

#Bandits
  (8.1, 0, 0.0, [[store_num_parties_of_template, reg(2), "pt_mountain_bandits"], [lt,reg(2),6]],
                     [[store_random,reg(5),num_mountain_bandit_spawn_points],
                      [val_add,reg(5),"p_mountain_bandit_spawn_point"],
                      [set_spawn_radius,1],
                      [spawn_around_party,reg(5),"pt_mountain_bandits"], 
                      ]),

  (8.1, 0, 0.0, [[store_num_parties_of_template, reg(2), "pt_forest_bandits"], [lt,reg(2),6]],
                     [[store_random,reg(5),num_forest_bandit_spawn_points],
                      [val_add,reg(5),"p_forest_bandit_spawn_point"],
                      [set_spawn_radius,1],
                      [spawn_around_party,reg(5),"pt_forest_bandits"], 
                      ]),


  (24.0, 0.0, 0.0,
   [
       (ge,"$mountain_bandits_paid",1)
    ],
   [
       (val_sub,"$mountain_bandits_paid",1),
       (eq,"$mountain_bandits_paid",0),
       (set_relation,"fac_mountain_bandits", "fac_player_faction", "$mountain_bandits_relation_original"),
    ]
   ),

  (24.0, 0.0, 0.0,
   [
       (ge,"$forest_bandits_paid",1)
    ],
   [
       (val_sub,"$forest_bandits_paid",1),
       (eq,"$forest_bandits_paid",0),
       (set_relation,"fac_forest_bandits", "fac_player_faction", "$forest_bandits_relation_original"),
    ]
   ),
#Deserters

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_deserters"),
                         (assign, "$pin_limit", 4),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),
  
  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_deserters"),
                         (assign, "$pin_limit", 4),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),
  
  (24.0, 0.0, 0.0,
   [
       (ge,"$vaegir_deserters_paid",1)
    ],
   [
       (val_sub,"$vaegir_deserters_paid",1),
       (eq,"$vaegir_deserters_paid",0),
       (set_relation,"fac_vaegir_deserters", "fac_player_faction", "$vaegir_deserter_relation_original"),
    ]
   ),

  (24.0, 0.0, 0.0,
   [
       (ge,"$swadian_deserters_paid",1)
    ],
   [
       (val_sub,"$swadian_deserters_paid",1),
       (eq,"$swadian_deserters_paid",0),
       (set_relation,"fac_swadian_deserters", "fac_player_faction", "$swadian_deserter_relation_original"),
    ]
   ),


#Swadians
  (0.0, 0.0, ti_once, [], [(assign,"$peak_swadian_foragers",4)]),
  (0.0, 0.0, ti_once, [], [(assign,"$peak_swadian_scouts",4)]),
  (0.0, 0.0, ti_once, [], [(assign,"$peak_swadian_harassers",3)]),
  (0.0, 0.0, ti_once, [], [(assign,"$peak_swadian_war_parties",2)]),
  
  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_foragers"),
                         (assign, "$pin_limit", "$peak_swadian_foragers"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_scouts"),
                         (assign, "$pin_limit", "$peak_swadian_scouts"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_patrol"),
                         (assign, "$pin_limit", "$peak_swadian_harassers"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_swadians"),
                         (assign, "$pin_party_template", "pt_swadian_war_party"),
                         (assign, "$pin_limit", "$peak_swadian_war_parties"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),
#Vaegirs
  (0.0, 0.0, ti_once, [], [(assign,"$peak_vaegir_foragers",4)]),
  (0.0, 0.0, ti_once, [], [(assign,"$peak_vaegir_scouts",4)]),
  (0.0, 0.0, ti_once, [], [(assign,"$peak_vaegir_harassers",3)]),
  (0.0, 0.0, ti_once, [], [(assign,"$peak_vaegir_war_parties",2)]),
  

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_foragers"),
                         (assign, "$pin_limit", "$peak_vaegir_foragers"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_scouts"),
                         (assign, "$pin_limit", "$peak_vaegir_scouts"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_patrol"),
                         (assign, "$pin_limit", "$peak_vaegir_harassers"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

  (10.2, 0, 0.0, [],
                     [
                         (assign, "$pin_faction", "fac_vaegirs"),
                         (assign, "$pin_party_template", "pt_vaegir_war_party"),
                         (assign, "$pin_limit", "$peak_vaegir_war_parties"),
                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
                    ]),

#Villains etc.
#  (14.2, 0, 0.0, [],
#                     [
#                         (assign, "$pin_faction", "fac_sea_raiders"),
#                         (assign, "$pin_party_template", "pt_sea_raiders"),
#                         (assign, "$pin_limit", 5),
#                         (call_script,"script_spawn_party_at_faction_town_if_below_limit"),
#                    ]),

  [14.1, 0, 0.0, [[store_num_parties_of_template, reg(2), "pt_sea_raiders"], [lt,reg(2),5]],
                     [[store_random,reg(5),num_sea_raider_spawn_points],
                      [val_add,reg(5),"p_sea_raider_spawn_point_1"],
                      [set_spawn_radius,1],
                      [spawn_around_party,reg(5),"pt_sea_raiders"], 
                      ]],

  [1.0, 0.0, ti_once, [], [[assign,"$peak_steppe_bandits",6]]],
  
  [10.1, 0, 0.0, [[store_num_parties_of_template, reg(2), "pt_steppe_bandits"], [lt,reg(2),"$peak_steppe_bandits"]],
                     [[store_random,reg(5),num_steppe_bandit_spawn_points],
                      [val_add,reg(5),"p_steppe_bandit_spawn_point"],
                      [set_spawn_radius,1],
                      [spawn_around_party,reg(5),"pt_steppe_bandits"], 
                      [val_add,"$num_steppe_bandits",1]]],

  [1.0, 0.0, ti_once, [], [[assign,"$peak_black_khergit_raiders",3]]],
  
  [10.1, 0, 0.0, [[store_num_parties_of_template, reg(2), "pt_black_khergit_raiders"], [lt,reg(2),"$peak_black_khergit_raiders"]],
                     [[store_random,reg(5),num_black_khergit_spawn_points],
                      [val_add,reg(5),"p_black_khergit_spawn_point"],
                      [set_spawn_radius,1],
                      [spawn_around_party,reg(5),"pt_black_khergit_raiders"], 
                      [val_add,"$num_black_khergit_raiders",1]]],


#
  (10.1, 0, 0.0, [],
                     [
                         (assign, "$pin_party_template", "pt_refugees"),
                         (assign, "$pin_limit", 5),
                         (call_script,"script_spawn_party_at_random_town_if_below_limit"),
                    ]),

  (10.1, 0, 0.0, [],
                     [
                         (assign, "$pin_party_template", "pt_farmers"),
                         (assign, "$pin_limit", 6),
                         (call_script,"script_spawn_party_at_random_town_if_below_limit"),
                    ]),

  [1.0, 96.0, ti_once, [], [[assign,"$peak_dark_hunters",3]]],
  
  (10.1, 0, 0.0, [],
                     [
                         (assign, "$pin_party_template", "pt_dark_hunters"),
                         (assign, "$pin_limit", "$peak_dark_hunters"),
                         (call_script,"script_spawn_party_at_random_town_if_below_limit"),
                    ]),

#Companion quests
  [0.1, 0, ti_once, [[neq,"$quest_given_scout_waypoints",0],
                     [eq,"$quest_complete_scout_wp1",0],
#                     [store0_distance_to_town_from_party,waypoint_1],
                     [lt,reg(0),1]], [[assign,"$quest_complete_scout_wp1",1],
#                                      [complete_quest,qst_scout_waypoint_1],
#                                      [hide_town, waypoint_1]
                                      ]],
  


  (0, 0, ti_once,
   [
       (entering_town,"p_town_1"),
       (main_party_has_troop,"trp_borcha"),
       (eq,"$borcha_freed",0)
    ],
   
   [
       (assign,"$borcha_arrive_sargoth_as_prisoner",1),
       (start_map_conversation,"trp_borcha")
    ]
   ),

  (1, 0, ti_once,
   [
      (map_free,0),
      (eq,"$borcha_asked_for_freedom",0),
      (main_party_has_troop,"trp_borcha")
    ],
   [
       (start_map_conversation,"trp_borcha")
    ]
   ),
  
  (2, 0, ti_once,
   [
      (map_free, 0),
      (neq,"$borcha_asked_for_freedom",0),
      (eq,"$borcha_freed",0),
      (main_party_has_troop,"trp_borcha")
    ],
   [
       (start_map_conversation,"trp_borcha"),
    ]
   ),

#########################################################################
# Random Governer Quest triggers
#########################################################################

# Enable nobleman's party 48 hours after the flag is set.
  (1.0, 48.0, 1.0,
   [
       (eq,"$nobleman_quest_nobleman_enable",1)
    ],
   [
       (assign,"$nobleman_quest_nobleman_active",1),
       (enable_party,"$nobleman_quest_party_id"),
       (assign,"$nobleman_quest_nobleman_enable",0),
    ]
   ),
# Stop nobleman's party every few hours
  (1.5, 0.0, 0.2,
   [
       (eq,"$nobleman_quest_nobleman_active",1)
    ],
   [
       (party_set_ai_behavior,"$nobleman_quest_party_id",ai_bhvr_hold),
    ]
   ),

  (0.9, 0, 0.2,
   [
       (eq,"$nobleman_quest_nobleman_active",1)
    ],
   [
       (party_set_ai_behavior,"$nobleman_quest_party_id",ai_bhvr_travel_to_party),
    ]
   ),
# Fail nobleman quest if he reaches target town
  (1.3, 0, 0.0,
   [
       (eq,"$nobleman_quest_nobleman_active",1),
       (party_is_in_town,"$nobleman_quest_party_id","$nobleman_quest_target_town")
    ],
   [
       (assign,"$nobleman_quest_failed",1),
       (assign,"$nobleman_quest_nobleman_active",0),
       (display_message,"str_nobleman_reached_destination"),
       (fail_quest,"qst_capture_nobleman"),
       (remove_party,"$nobleman_quest_party_id"),
    ]
   ),
# Fail nobleman quest if quest is completed but our 
  (0.1, 0.0, 0.0,
   [
       (eq,"$nobleman_quest_nobleman_active",1),
       (neg|main_party_has_troop,"trp_nobleman"),
       (neg|party_is_active,"$nobleman_quest_party_id")
    ],
   [
       (assign,"$nobleman_quest_failed",1),
       (fail_quest,"qst_capture_nobleman"),
       (assign,"$nobleman_quest_nobleman_active",0),
    ]
   ),
# Raiders quest
  (0.95, 0.0, 0.2,
   [
       (eq,"$raider_quest_active",1)
       ],
   [
       (party_set_ai_behavior,"$raider_quest_party_id",ai_bhvr_hold),
  ]),

  (0.7, 0, 0.2,
   [
       (eq,"$raider_quest_active",1)
    ],
   [
       (party_set_ai_behavior,"$raider_quest_party_id",ai_bhvr_travel_to_party),
    ]
   ),
  
  (0.1, 0.0, 0.0,
   [
       (eq,"$raider_quest_active",1),
       (neg|party_is_active,"$raider_quest_party_id")
    ],
   [
       (assign,"$raider_quest_succeeded",1),
       (assign,"$raider_quest_active",0)
    ]
   ),
  
  (1.3, 0, 0.0,
   [
       (eq,"$raider_quest_active",1),
       (party_is_in_town,"$raider_quest_party_id","$raider_quest_target_town")
    ],
   [
       (assign,"$raider_quest_failed",1),
       (assign,"$raider_quest_active",0),
       (display_message,"str_raiders_reached_base"),
       (fail_quest,"qst_hunt_down_raiders"),
       (remove_party,"$raider_quest_party_id"),
    ]
   ),
#########################################################################
# Random MERCHANT quest triggers
####################################  
 # Apply interest to merchants guild debt  1% per week
  (24.0 * 7, 0.0, 0.0,
   [],
   [
       (val_mul,"$debt_to_merchants_guild",101),
       (val_div,"$debt_to_merchants_guild",100)
    ]
   ),
# Deliver food to tavern  
  (24.0, 0, 1.0,
   [
       (eq,"$deliver_wine_quest_active",1),
       (store_current_day,reg(3)),
       (lt,"$deliver_wine_quest_end_day",reg(3)),
     ],
   [
       (fail_quest,"qst_deliver_wine"),
       (complete_quest,"qst_deliver_wine"),
       (assign,"$deliver_wine_quest_active",0),
       (val_add,"$debt_to_merchants_guild","$deliver_wine_quest_debt")
     ]
   ),
# Escort merchant caravan:
  (0.1, 0.0, 0.1, [[eq,"$escort_merchant_caravan_quest_active",1],
                   [eq,"$escort_merchant_caravan_mode",1]], [[party_set_ai_behavior,"$merchant_caravan_id",ai_bhvr_hold]]),
  (0.02, 0.0, 0.1, [[eq,"$escort_merchant_caravan_quest_active",1],
                   [eq,"$escort_merchant_caravan_mode",0],
                   [store_distance_to_party_from_party, reg(0),"$merchant_caravan_id"],
                   [ge,reg(0),1]], [[party_set_ai_behavior,"$merchant_caravan_id",ai_bhvr_track_party],
                                    [party_set_ai_object,"$merchant_caravan_id",0]]),
  (0.02, 0.0, 0.1, [[eq,"$escort_merchant_caravan_quest_active",1],
                   [eq,"$escort_merchant_caravan_mode",0],
                   [store_distance_to_party_from_party, reg(0),"$merchant_caravan_id"],
                   [lt,reg(0),1]], [[party_set_ai_behavior,"$merchant_caravan_id",ai_bhvr_hold]]),

  (0.1, 0, 0.0, [[eq,"$escort_merchant_caravan_quest_active",1],
                 [neg|party_is_active,"$merchant_caravan_id"]],
                         [[fail_quest,"qst_escort_merchant_caravan"],
                          [complete_quest,"qst_escort_merchant_caravan"],
                           [assign,"$escort_merchant_caravan_quest_active",0]]),

# Troublesome bandits
  (0.3, 0.0, 1.1, [[eq,"$troublesome_bandits_quest_active",1],
                   [store_num_parties_destroyed,reg(3),"pt_troublesome_bandits"],
                   [lt,"$troublesome_bandits_eliminated",reg(3)],
                   (store_num_parties_destroyed_by_player, ":num_quest_bandits_destroyed_by_player", "pt_troublesome_bandits"),
                   [eq,":num_quest_bandits_destroyed_by_player","$troublesome_bandits_eliminated_by_player"],
                   ], [[display_message,"str_bandits_eliminated_by_another"],
                       [fail_quest,"qst_troublesome_bandits"],
                       [complete_quest,"qst_troublesome_bandits"],
                       [assign,"$troublesome_bandits_quest_active",0]]),

  (0.3, 0.0, 1.1, [[eq,"$troublesome_bandits_quest_active",1],
                   [store_num_parties_destroyed,reg(3),"pt_troublesome_bandits"],
                   [lt,"$troublesome_bandits_eliminated",reg(3)],
                   (store_num_parties_destroyed_by_player, ":num_quest_bandits_destroyed_by_player", "pt_troublesome_bandits"),
                   [neq,":num_quest_bandits_destroyed_by_player","$troublesome_bandits_eliminated_by_player"],
                   ], [[succeed_quest,"qst_troublesome_bandits"],
                       [assign,"$troublesome_bandits_quest_active",0],
                       [assign,"$troublesome_bandits_quest_succeeded",1]]),
# Kidnapped girl:
  (0, 0, 0,
   [
       (entering_town,"$kidnapped_girl_quest_giver_town"),
       (main_party_has_troop,"trp_kidnapped_girl")
       ],
   [
       (start_map_conversation,"trp_kidnapped_girl"),
       (assign,"$talking_with_kidnapped_girl",1),
       (assign,"$kidnapped_girl_brought_back",1)
       ]
   ),
  
  (2.0, 0, 0,
   [
      (check_quest_active,"qst_kidnapped_girl"),
      (main_party_has_troop,"trp_kidnapped_girl"),
      (eq,"$kidnapped_girl_bandits_attacked",1),
      (eq,"$kidnapped_girl_joined",0),
    ],
   [
      (assign,"$kidnapped_girl_joined",1),
    ]
   ),
 
]
